package jnpf.controller;

import io.swagger.annotations.Api;
import jnpf.base.ActionResult;
import jnpf.service.*;
import jnpf.util.RsaEncrypt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @ClassName ZXGL_AI_InterfaceController
 * @Description AI接口
 * @Author ZCX
 * @Date 2025-03-19
 * @Version 1.0
 **/
@Slf4j
@RestController
@Api(tags = "ZXGL_FR", value = "zxgl")
@RequestMapping("/ZXGL_FR")
public class ZXGL_FR_InterfaceController {

    @Autowired
    private ZXGL_FR_Service zxgl_fr_service;

    @GetMapping("/login")
    public ActionResult login() {
        try {
            String username = "13933196237";
            String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgmKJIGF2BUmpB/YL68KLE2kXhr6l5bI7\n" +
                    "hjZrSipnps10Yzw+7yhFzbKQm+4yjnhGY2iZKZ1JS60TXCfcAD2dnruhbURTBxLTF9XEfTHG/LYs\n" +
                    "NyLv0PgME8qTNu5SiIo3wyLLCI2CBgx9PGQK+V4s2gEo+hlumNoyiXvz861pb3WY8fHdbZ6wL2E9\n" +
                    "apUDykH4EqSi3xQJlSGD+UaYbbDFomQtut544aPbmjQvzN3bYTOGMkknCBAxu4jfvFN9rRCJl8eZ\n" +
                    "WhHq7mY7cAdGR8esgUEIEh1Aa3iyc724B/Q0zHxz+jm50hSOXe6BijivYugXDIWAc7mZjaSdKgUc\n" +
                    "kzM0NQIDAQAB";

            //加密后的ssoToken,可以在前台界面进行解密测试
            String encrypt = RsaEncrypt.encrypt(username, publicKey);
            System.out.println("encrypted username: " + encrypt);

            //encode后的token,可以直接放于url上进行单点
            String encode = URLEncoder.encode(encrypt, "UTF-8");
            System.out.println("ssoToken: " + encode);

            return ActionResult.success("生成成功", encode);
        }catch (UnsupportedEncodingException ux){
            ux.printStackTrace();
        }
        return ActionResult.fail("生成失败");
    }
}
